Northwoods.GoXam.Model Namespace > GraphModel<NodeType,NodeKey> Class : CopyNode2 Method |
Protected Overridable Sub CopyNode2( _ ByVal oldnodedata As NodeType, _ ByVal env As GraphModel(Of NodeType,NodeKey), _ ByVal newnodedata As NodeType, _ ByVal newgroup As NodeType, _ ByVal newmembers As IEnumerable(Of NodeType), _ ByVal newfroms As IEnumerable(Of NodeType), _ ByVal newtos As IEnumerable(Of NodeType) _ )
protected virtual void CopyNode2( NodeType oldnodedata, GraphModel<NodeType,NodeKey> env, NodeType newnodedata, NodeType newgroup, IEnumerable<NodeType> newmembers, IEnumerable<NodeType> newfroms, IEnumerable<NodeType> newtos )
You will want to override this method if the node data should have any references to copied data. Otherwise the copied node will appear to have links to the original nodes, not to the copied nodes.
Your overridden method may want to do something like what this method does by default: // this assumes the node data has a modifiable collection of "from" node references // if not, you could instead construct your own list of keys and call ModifyFromNodeKeys if (this.FromNodesPath != "" && newfroms != null) { // remove any old keys; not needed if the copied property value is empty foreach (NodeKey k in FindFromNodeKeysForNode(newnodedata).OfType<NodeKey>().ToList()) { DeleteFromNodeKey(newnodedata, k); } // add new keys (which should be different from the old keys) foreach (NodeType newfrom in newfroms) { NodeKey newfromkey = FindKeyForNode(newfrom); InsertFromNodeKey(newnodedata, newfromkey); } } // this assumes the node data has a modifiable collection of "to" node references; // if not, you could instead construct your own list of keys and call ModifyToNodeKeys if (this.ToNodesPath != "" && newtos != null) { // remove any old keys; not needed if the copied property value is empty foreach (NodeKey k in FindToNodeKeysForNode(newnodedata).OfType<NodeKey>().ToList()) { DeleteToNodeKey(newnodedata, k); } // add new keys (which should be different from the old keys) foreach (NodeType newto in newtos) { NodeKey newtokey = FindKeyForNode(newto); InsertToNodeKey(newnodedata, newtokey); } } // this assumes the node data has a reference to its container group if (this.GroupNodePath != "" && newgroup != null) { ModifyGroupNodeKey(newnodedata, FindKeyForNode(newgroup)); } // this assumes the node data has a modifiable collection that InsertMemberNodeKey can work with; // if not, you could instead construct your own list of keys and call ModifyMemberNodeKeys. if (this.MemberNodesPath != "" && newmembers != null) { // remove any old keys; not needed if the copied property value is empty foreach (NodeKey k in FindMemberNodeKeysForNode(newnodedata).OfType<NodeKey>().ToList()) { DeleteMemberNodeKey(newnodedata, k); } // add new keys (which should be different from the old keys) foreach (NodeType newmem in newmembers) { NodeKey newmemkey = FindKeyForNode(newmem); InsertMemberNodeKey(newnodedata, newmemkey); } }